package com.cutepeer.notes.server;

import java.util.ArrayList;
import java.util.List;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONObject;

import android.content.Context;

import com.cutepeer.libonline.server.KEY;
import com.cutepeer.libonline.server.connect.JsonParser;
import com.cutepeer.libonline.settings.UserSigned;

/**
 * @since Wednesday, November 19, 2014
 * @author hoangcaomobile
 *
 */
public class Connect {

	public static String notes = "notes";
	public static String noteId = "noteId";
	public static String noteText = "noteText";
	public static String noteTime = "noteTime";

	private static JsonParser jsonParser = new JsonParser();

	public static JSONObject get(Context mContext, int mPage) {
		List<NameValuePair> params = new ArrayList<NameValuePair>();
		params.add(new BasicNameValuePair(KEY.userAccount, UserSigned.getUserAccount(mContext)));
		params.add(new BasicNameValuePair(KEY.userPassword, UserSigned.getUserPassword(mContext)));
		params.add(new BasicNameValuePair("page", Integer.toString(mPage)));
		JSONObject json = jsonParser.getJSONFromUrl(API.noteGet, params);
		return json;
	}

	public static JSONObject insert(Context mContext, String mNoteText) {
		List<NameValuePair> params = new ArrayList<NameValuePair>();
		params.add(new BasicNameValuePair(KEY.userAccount, UserSigned.getUserAccount(mContext)));
		params.add(new BasicNameValuePair(KEY.userPassword, UserSigned.getUserPassword(mContext)));
		params.add(new BasicNameValuePair("noteText", mNoteText));
		JSONObject json = jsonParser.getJSONFromUrl(API.noteInsert, params);
		return json;
	}

}
